
package org.sunspotworld.demo;

import com.sun.squawk.util.MathUtils;
/**
 *
 * @author kyle.murphy
 */
public class AV {
    public final static short GLOBAL_FACTOR = 1;
    public final static float MAX_AV_VALUE = 1.0f;
    public final static float DEFAULT_AV_VALUE = 0.5f;
    public final static float MIN_AV_VALUE = 0.0f;
    private float m_arousal, m_valence;
    private boolean m_isGlobal;

    public AV()
    {
        m_isGlobal = false;
        m_arousal = DEFAULT_AV_VALUE;
        m_valence = DEFAULT_AV_VALUE;
    }

    public AV(float arousal, float valence)
    {
        m_isGlobal = false;
        m_arousal = arousal;
        m_valence = valence;
    }

    public AV(float arousal, float valence, boolean isGlobal)
    {
        m_isGlobal = isGlobal;
        m_arousal = arousal;
        m_valence = valence;
    }

    public void setArousal(float arousal)
    {
        if(arousal > MAX_AV_VALUE)
        {
            m_arousal = MAX_AV_VALUE;
            //return;
        }

        else if (arousal < MIN_AV_VALUE)
        {
            m_arousal = MIN_AV_VALUE;
            //return;
        }
        else
        {
            m_arousal = arousal;
        }
        
        System.out.println("A <= " + m_arousal);
    }

    public void setValence(float valence)
    {
        if(valence > MAX_AV_VALUE)
        {
            m_valence = MAX_AV_VALUE;
            //return;
        }

        else if (valence < MIN_AV_VALUE)
        {
            m_valence = MIN_AV_VALUE;
            //return;
        }
        else
        {
            m_valence = valence;
        }
        
        System.out.println("V <= " + m_valence);
    }

    public void setAV(float arousal, float valence)
    {
        setArousal(arousal);
        setValence(valence);
    }

    public float getArousal()
    {
        return m_arousal;
    }

    public float getValence()
    {
        return m_valence;
    }

    public void setIsGlobal(boolean b)
    {
        m_isGlobal = b;
    }

    public boolean isGlobal()
    {
        return m_isGlobal;
    }

    public float magnitude()
    {
        float  arousalSquared = (float) MathUtils.pow((float)m_arousal, (float)2.0);
        float valenceSquared = (float)MathUtils.pow((float)m_valence, 2.0);
        return (float) Math.sqrt(arousalSquared + valenceSquared);
    }
}
